package momo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;

import momo.Image;

/**
 * 
 *@author Mohamed Mosa
 *@version April 29th
 *
 */

public class Library implements Serializable{
    ArrayList<Image> images;
    String name;
    static Image img = new Image("wazup");

    public Library(String name) {
        super();
        this.name = name;
        this.images = new ArrayList<Image>();
    }


    /**
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }
    
    public int getSize(){
       return images.size();
    }
    
    /**
     * @return library
     */
    //public ArrayList<Image> getLibrary() {
    //    return images;
    //}

    /**
     * @param imgLibrary
     */
    //public void setLibrary(ArrayList<Image> imgLibrary) {
    //  this.images = images;
    //}
    
    public void add (final Image img) {
        images.add(img);
    }

    public void remove(final Image img){
        images.remove(img);  
    }
    
    public void printImages() {
        for (final Image img : images) {
            System.out.println(img);
        }
    }

    public void save() throws IOException {
        //SERIALIZATION
		try {
			FileOutputStream fileStream = new FileOutputStream("library.lib");
			ObjectOutputStream os = new ObjectOutputStream(fileStream);
			os.writeObject(img);
			os.close();
			
		} catch (FileNotFoundException e) {
			
			e.printStackTrace();
		}
    }
    
    public void load() throws IOException {
        //DESERIALIZATION
        try {
			FileInputStream filestream = new FileInputStream("library.lib");
			ObjectInputStream is = new ObjectInputStream(filestream);
			Object one = is.readObject();
			Image image = (Image) img;
			//System.out.println(one);
			System.out.println(image);
			is.close();	
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
    }
}